<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>轮播图</title>
    <style>
        .wrap {
            width: 600px;
            height: 400px;
            margin: 100px auto;
            position: relative;
            overflow: hidden;
        }

        .navs {
            width: 4200px;
            height: 100%;
            position: absolute;
            left: -600px;
            top: 0;
        }

        .navs li img {
            width: 100%;
            height: 100%;
        }

        #bots {
            display: flex;
            justify-content: center;
            align-items: center;
            width: 600px;
            height: 40px;
            background: #000;
            text-align: center;
            position: absolute;
            bottom: 0;
            left: 0;
        }

        #bots li {
            width: 20px;
            height: 20px;
            border-radius: 50%;
            background-color: #ccc;

            margin-left: 10px;
            float: left;
        }

        #bots .active {
            background-color: #f00;
        }
    </style>
</head>

<body>
    <div class="wrap" id="box">
        <ul id="navs" class="navs">
            <li><a href=""><img src="https://picsum.photos/200/300?=1" alt=""></a></li>
            <li><a href=""><img src="https://picsum.photos/200/300?=2" alt=""></a></li>
            <li><a href=""><img src="https://picsum.photos/200/300?=3" alt=""></a></li>
            <li><a href=""><img src="https://picsum.photos/200/300?=4" alt=""></a></li>
            <li><a href=""><img src="https://picsum.photos/200/300?=5" alt=""></a></li>
            <li><a href=""><img src="https://picsum.photos/200/300?=6" alt=""></a></li>
            <li><a href=""><img src="https://picsum.photos/200/300?=7" alt=""></a></li>
        </ul>
        <ul id="bots">
            <li class="bot active"></li>
            <li class="bot"></li>
            <li class="bot"></li>
            <li class="bot"></li>
            <li class="bot"></li>
        </ul>
    </div>

    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script>
        window.onload = function () {
            let num = 1
            let timer = null
            let i = 0
            function swiper(params) {
                timer = setInterval(() => {
                    num++

                    if (num > 6) {
                        $("#box").css("left", -600)
                        num = 2
                    }
                    $('#navs').animate({
                        left: -num * 600
                    }, 500)

                    i++
                    if (i > 4) {
                        i = 0

                    }
                    $("#bots li").eq(i).addClass("active").siblings().removeClass("active");


                }, 20);
            }

            $(".wrap".mouseover(() => {
                clearInterval(timer)
            }))
            $(".wrap".mouseout(() => {
                swiper()
            }))
        }

    </script>
</body>

</html>